package data.input;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;

import org.joda.time.LocalDate;

import data.enums.Index;
import data.transform.DateTransform;
import entities.IndexTuple;

public class WallStreetJournalCsv extends Data {

	private static final long serialVersionUID = 1047958649738586639L;

	public WallStreetJournalCsv(Index index) throws FileNotFoundException, IOException {
		initializeTuplesMap(index);
	}

	@Override
	protected void initializeTuplesMapWithoutClassification(Index indexName) throws FileNotFoundException, IOException {

		@SuppressWarnings("resource")
		BufferedReader reader = new BufferedReader(new FileReader(indexName.toString() + ".csv"));

		// first line does not contain data
		String line = reader.readLine();

		while ((line = reader.readLine()) != null) {

			String[] data = line.split(";");

			LocalDate date = DateTransform.wallStreetJournalCsvDateToLocalDate(data[0]);
			BigDecimal close = new BigDecimal(data[5].replace(",", "."));

			tuplesMap.put(date, new IndexTuple(date, close));

		}
	}
	
}
